<!DOCTYPE html>
<html lang="en">
<head>
    <{include file="header.html"}>
    <title>章节管理-<{$user_data['school_name']}>-德安信会计在线教育平台</title>
</head>
<body>
<div class="wrap">
    <!--star left-->
    <div class="column">
        <{include file="left_menu.html"}>
    </div>
    <div id="ContMianBox">
        <!--star子栏目-->
        <div class="sub-colum">
            <div class="tit"><{$left_menu_min.menu}></div>
            <ul>
                <{foreach from=$left_menu_min.list item=item}>
                <li <{if $item['url'] == $left_menu_min.curr}>class="curr"<{/if}>><a href="<{$item['url']}>"><{$item['name']}></a></li>
                <{/foreach}>
            </ul>
        </div>
        <!--end子栏目-->
        <!--end left-->
        <div class="container narrow">
            <!--star conter-->
            <div class="cetContent">
                <div class="tit p-lr20">
                    <span><a href="/subject">科目管理</a></span>
                    <span class="curr"><a href="/subject/chapter_list">章节管理</a></span>
                </div>
                <!--star内容区域-->
                <div class="mainScroll">
                    <div class="mainContainer line-all">
                        <!--star 001-->
                        <form class="layui-form layui-form-pane" method="post" action="<{$post_url}>">
                            <input type="hidden" name="id" value="<{$chapter_info.id|default:'0'}>" />

                            <div class="layui-form-item">
                                <label class="layui-form-label">章节名称</label>
                                <div class="layui-input-block">
                                    <input type="text" name="title" value="<{$chapter_info.title|default:''}>" class="layui-input" >
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">科目</label>
                                <div class="layui-input-block">
                                    <select name="subject_id" id="subject" lay-filter="subject">
                                        <option value="0">请选择科目</option>
                                        <{foreach from=$subject_list item=sitem}>
                                            <option value="<{$sitem.id}>" <{if isset($chapter_info.subject_id) AND $chapter_info.subject_id == $sitem.id}>selected<{/if}>><{$sitem.title}></option>
                                        <{/foreach}>
                                    </select>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">章节</label>
                                    <div class="layui-input-block">
                                        <select name="parent_id" id="chapter_id" lay-filter="chapter_id">
                                            <option value="0">请选择章节</option>
                                            <{if $chapter_list_data|count  > 0}>
                                                <{foreach from=$chapter_list_data item=item}>
                                                <{if $item.id != $chapter_info.id}>
                                                <option <{if $item.id == $chapter_info.parent_id}> selected <{/if}> value="<{$item.id}>"><{$item.title}></option>
                                                <{/if}>
                                                <{/foreach}>
                                            <{/if}>
                                        </select>
                                    </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">排序</label>
                               <div class="layui-input-inline">
                                    <input type="text" name="sort" value="<{$chapter_info.sort|default:'0'}>" class="layui-input" >
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">是否显示</label>
                                <div class="layui-input-block">
                                    <{assign var="is_chapter" value=$privilege_info->is_chapter|default:"1"}>
                                    <input type="checkbox" <{if $is_chapter == 1}> checked<{/if}> name="is_chapter" lay-skin="switch" lay-filter="switchTest" value="1" >
                                </div>
                            </div>

                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </form>
                        <!--end 001-->

                    </div>

                </div>
                <!--end内容区域-->
        </div>
    </div>
</div>
<{include file="footer.html"}>
<script type="text/javascript">
    layui.use(['form','jquery'], function(){
        var form = layui.form(),$ = layui.jquery;
        
        form.on('select(subject)', function(data){
            var ii = layer.load();
            var subject_id = $(data.elem).val();
            $("#chapter_id").html('<option value="0">顶级章节</option>');  
            form.render('select');
            $.ajax({
                type: "POST",
                url: "/tiku/ignore_get_subject_chapter",
                dataType:"json",
                data:{subject_id:subject_id},
                success: function(result){

                    layer.close(ii);
                    if(result.code == 1){
                        var html ='';
                        $.each(result.chapter_list, function(i, obj) {
                            html += '<option value="'+obj.id+'">'+obj.title+'</option>';
                            // if(obj.sub){
                            //     $.each(obj.sub, function(j, obj1) {

                            //         html += '<optgroup label="'+ obj1.title+'">';
                            //         if(obj1.sub){
                            //             $.each(obj1.sub, function(k, obj2) {
                            //                 html += '<option value="'+obj2.id+'">'+obj2.title+'</option>';
                            //             });
                            //         }
                            //         html += '</optgroup>'
                            //     });
                            // }
                        });
                        $("#chapter_id").append(html);
                        form.render('select');
                    }
                }
            });
        });
    });
</script>
</body>
</html>